<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="../include/header.jsp" />
<script type="text/javascript" src="<c:url value='/htmlRes/js/tableAddDelete.js'/>"></script>
<script type="text/javascript" src="<c:url value='/htmlRes/js/datepicker/jquery.ui.core.js'/>"></script>
<script type="text/javascript" src="<c:url value='/htmlRes/js/datepicker/jquery.ui.datepicker.js'/>"></script>
<!-- 기본 CSS 설정 완료시 삭제. -->
<script type="text/javaScript">
<!--
	/* pagination 페이지 링크 function */
	function listPage(){
		$('#writeForm').attr('action', '<c:url value="/servicearea/serviceareaList.do"/>');
		$('#writeForm').submit();
	}
	
	function saveFormPage() {
		if($('#idDuplCheck').val() == "false"){
			alert("아이디 중복확인을 해주세요");
			return;
		}
		if($.trim($('#ssa_pass_word').val()) == ''){
			if($.trim($('#pass_word').val()) == ""){
				alert("비밀번호를 입력하세요.");
				return;
			}else if($.trim($('#pass_confirm').val()) == ""){
				alert("비밀번호를 확인을 입력하세요.");
				return;
				
			}else if($.trim($('#pass_word').val()) != $.trim($('#pass_confirm').val())){
				alert("비밀번호를 확인해 주세요.");
				return;
			}else{
				$('#ssa_pass_word').val($('#pass_word').val());
			}
		}else{
			if($.trim($('#pass_word').val()) != ""){
				if($.trim($('#pass_word').val()) == $.trim($('#pass_confirm').val())){
					$('#ssa_pass_word').val($('#pass_word').val());
				}else{
					alert("비밀번호를 확인해 주세요.");
					return;
				}
			}
		}
		$('#writeForm').attr('action', '<c:url value="/servicearea/serviceareaSave.do"/>');
		$('#writeForm').submit();
	}
	
	function loginIdCheck(){
		var checkId = $.trim($('#ssa_login_id').val());
		if(checkId==''){
			alert('아이디를 입력하세요.');
			return;
		}
		$.ajax({
			type : "POST" ,
			url : "<c:url value='/login/loginIdCheck.do'/>",
			dataType: 'html',
			data : 'chkId='+checkId,
			success: function(data) {
				if(data == "true"){
					//$('#resultInfoLoginId').html('사용할수 있는 아이디 입니다.');
					$('#resultInfoLoginId').html('확인 되었습니다.');
					$('#idDuplCheck').val("true");
				}else{
					//$('#resultInfoLoginId').html('이미 사용중인 아이디 입니다.');
					$('#resultInfoLoginId').html('이미 사용중인 아이디 입니다.');
					$('#idDuplCheck').val("false");
				};
			}, 
			error: function(request, status, err) {
				alert(request.status);
			}
		});
	}
	
	$(document).ready(function(){
		if($('#ssa_area_key').val() == ''){
			$('#ssa_login_id').keyup(function(){
				$('#idDuplCheck').val("false");
				var checkId = $.trim($('#ssa_login_id').val());
				var regExp = /[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]/;
				if(regExp.test(checkId)) {
					$('#resultInfoLoginId').html("영문, 숫자, -, _, 조합만  사용하실수 있습니다.");
					$('#checkId').hide();
		        }else{
		        	$('#resultInfoLoginId').html("");
					$('#checkId').show();
		        }
			});
		}
		$('#checkId').click(function(e){
			e.preventDefault();
			loginIdCheck();
		});
		$( "#ssa_serv_sdate" ).datepicker();
		$( "#ssa_serv_edate" ).datepicker();
		$('#managerTableApdRow').click(function(e){
			e.preventDefault();
			$('#serviceareaManagerTable').appendRow({sampleTRObj:"sampleTr"});
		});
		$('#managerTableDelRow').click(function(e){
			e.preventDefault();
			$('#serviceareaManagerTable').deleteRow();
		});
	});
-->
</script>
<!-- contents s -->
<div class="container" id="container">
	<span class="round lt">&nbsp;</span>
	<span class="round rt">&nbsp;</span>
	<span class="round lb">&nbsp;</span>
	<span class="round rb">&nbsp;</span>
	<div class="container_area">
	<form name="writeForm" id="writeForm" action="<c:url value="/servicearea/serviceareaWriteForm.do"/>" method="post">
		<input type="hidden" name="ssa_area_key" id="ssa_area_key" value="${resultVO.ssa_area_key }"/>
		<input type="hidden" name="ssa_pass_word" id="ssa_pass_word" value="${resultVO.ssa_pass_word }"/>
		<h2 class="tit_h2">휴게소 관리</h2>
			<jsp:include page="../include/navi.jsp" />
			<!--<h3 class="tit_h3">기본 정보</h3>-->
				
               <div class="table_wrap"><!-- D : table은 div table_wrap 싸고감 -->
				<table summary="아이디 비밀번호 확인 입니다" class="table_write">
					<caption>아이디 비밀번호 확인</caption>
					<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
						<col width="18%" />
						<col width="32%" />
						<col width="18%" />
						<col width="32%" />
					</colgroup>
					<tbody>
						<tr>
                           	<th scope="row"><label for="ssa_login_id">아이디</label></th>
							<td class="alL" colspan="3">
								<c:if test="${empty resultVO.ssa_area_key }">
									<input type="text" name="ssa_login_id" id="ssa_login_id" class="width_50" maxlength="15"/>
									<input type="hidden" id="idDuplCheck" value="false" />
									<a href="#checkId" class="btn_tb" id="checkId">중복확인</a><span style="color:red" id="resultInfoLoginId"> ${error_ssa_login_id }</span>
								</c:if>
								<c:if test="${!empty resultVO.ssa_area_key }">
									<input type="text" name="ssa_login_id" id="ssa_login_id" value="${resultVO.ssa_login_id }" class="width_50" readonly="readonly" />
									<input type="hidden" id="idDuplCheck" value="true" />
								</c:if>
							</td>
						</tr>
						<tr>
							<th scope="row"><label for="pass_word">비밀번호</label></th>
							<td class="alL">
								<input type="password" name="pass_word" id="pass_word" class="width_50" title="비밀번호를 입력하세요" />
								<span style="color:red">${error_ssa_pass_word }</span>
							</td>
							<th scope="row"><label for="ssa_pass_confirm">비밀번호 확인</label></th>
							<td class="alL">
								<input type="password" name="pass_confirm" id="pass_confirm" class="width_50" title="비밀번호를 입력하세요"/>
							</td>
						</tr>
                           
					</tbody>
				</table>
			</div>
			<div class="table_wrap">
				<table summary="현장명, 소재지, 권역, 담당자등 입력테이블 입니다" class="table_write">
					<caption>현장명, 소재지, 권역, 담당자등 입력테이블</caption>
					<colgroup> <!-- D : col width로 테이블 넓이 조절 -->
						<col width="15%" />
                           <col width="35%" />
                           <col width="15%" />
                           <col width="35%" />
					</colgroup>
					<tbody>
						<tr>
							<th scope="row"><label for="ssa_area_name">현장명</label></th>
							<td class="alL" colspan="3">
								<input type="text" name="ssa_area_name" id="ssa_area_name" value="${resultVO.ssa_area_name }" title="현장명을 입력하세요" class="width_50"/>
								<span style="color:red">${error_ssa_area_name }</span>
							</td>
						</tr>
						<tr>
							<th scope="row"><label for="ssa_area_addr">소새지</label></th>
							<td class="alL" colspan="3">
								<input type="text" name="ssa_area_addr" id="ssa_area_addr" value="${resultVO.ssa_area_addr }" title="소새지를 입력하세요" class="width_50"/>
							</td>
						</tr>
						<tr>
							<th scope="row"><label for="scc_code_key">권역 담당자</label></th>
							<td class="alL">
                               	<select name="scc_code_key" id="scc_code_key" title="권역을 선택하세요">
                               		<option value="">=== 권역 정보 ===</option>
                               		<c:forEach var="zoneList" items="${zoneList }">
										<option value="${zoneList.scc_code_key }" <c:if test="${zoneList.scc_code_key eq resultVO.scc_code_key }"> selected="selected"</c:if>>${zoneList.scc_code_name}[${zoneList.scc_zone_aname }]</option>
									</c:forEach>
								</select>
								<span style="color:red">${error_scc_code_key }</span>
							</td>
							<th scope="row"><label for="ssa_admin_id">담당자</label></th>
							<td class="alL">
								<select name="ssa_admin_id" id="ssa_admin_id" title="담당자를 선택하세요">
								<option value="">==== 담당자 정보 ====</option>
								<c:forEach var="userList" items="${userList }">
									<option value="${userList.sau_user_id }" <c:if test="${userList.sau_user_id eq resultVO.ssa_admin_id }">selected="selected"</c:if>>${userList.sau_user_name }(${userList.sau_user_hp })</option>
								</c:forEach>
								</select>
								<span style="color:red">${error_ssa_admin_id }</span>
							</td>
						</tr>
                    	<tr>
							<th scope="row"><label for="ssa_area_capa">시설용량</label></th>
							<td class="alL">
								<input type="text" name="ssa_area_capa" id="ssa_area_capa" value="${resultVO.ssa_area_capa }" title="시설용량을 입력하세요" class="width_50"/>
							</td>
							<th scope="row"><label for="ssa_builder">시공사</label></th>
							<td class="alL">
								<input type="text" name="ssa_builder" id="ssa_builder" value="${resultVO.ssa_builder }" title="시공사를 입력하세요" class="width_50"/>
							</td>
						</tr>
						<tr>
							<th scope="row"><label for="ssa_build_date">준공일자</label></th>
							<td class="alL">
								<input type="text" name="ssa_build_date" id="ssa_build_date" value="${resultVO.ssa_build_date }" title="준공일자를 입력하세요" class="width_50"/>
							</td>
							<th scope="row"><label for="ssa_serv_sdate">용역기간</label></th>
							<td class="alL">
								<input type="text" name="ssa_serv_sdate" id="ssa_serv_sdate" value="${resultVO.ssa_serv_sdate }" title="용역기간을 선택하세요"/> - <input type="text" name="ssa_serv_edate" id="ssa_serv_edate" value="${resultVO.ssa_serv_edate }" title="용역기간을 선택하세요"/>
							</td>
						</tr>
						<tr>
							<th scope="row"><label for="ssa_area_tel1">전화번호</label></th>
							<td class="alL">
								<input type="text" name="ssa_area_tel1" id="ssa_area_tel1" value="${resultVO.ssa_area_tel1 }" title="전화번호 앞자리를 선택하세요" />
								- <input type="text" name="ssa_area_tel2" id="ssa_area_tel2" value="${resultVO.ssa_area_tel2 }" title="전화번호 중간자리를 선택하세요" />
								- <input type="text" name="ssa_area_tel3" id="ssa_area_tel3" value="${resultVO.ssa_area_tel3 }" title="전화번호 마지막자리를 선택하세요" />
								<span style="color:red">${error_ssa_area_tel1 }</span><span style="color:red">${error_ssa_area_tel2 }</span><span style="color:red">${error_ssa_area_tel3 }</span>
							</td>
							<th scope="row"><label for="ssa_area_fax1">팩스번호</label></th>
							<td class="alL">
								<input type="text" name="ssa_area_fax1" id="ssa_area_fax1" value="${resultVO.ssa_area_fax1 }" title="팩스번호 앞자리를 선택하세요" />
								- <input type="text" name="ssa_area_fax2" id="ssa_area_fax2" value="${resultVO.ssa_area_fax2 }" title="팩스번호 중간자리를 선택하세요" />
								- <input type="text" name="ssa_area_fax3" id="ssa_area_fax3" value="${resultVO.ssa_area_fax3 }" title="팩스번호 마지막자리를 선택하세요" />
								<span style="color:red">${error_ssa_area_fax1 }</span><span style="color:red">${error_ssa_area_fax2 }</span><span style="color:red">${error_ssa_area_fax3 }</span>
							</td>
						</tr>
						<c:if test="${loginSessionInfo.admin }">
						<tr>
							<th scope="row"><label for="ssa_flag_yn">상태</label></th>
							<td class="alL" colspan="3">
								사용 <input type="radio" name="ssa_flag_yn" id="ssa_flag_yn" value="Y" <c:if test="${resultVO.ssa_flag_yn eq 'Y' or empty resultVO.ssa_flag_yn}">checked="checked"</c:if> /> 
								삭제 <input type="radio" name="ssa_flag_yn" id="ssa_flag_yn" value="N" <c:if test="${resultVO.ssa_flag_yn eq 'N' }">checked="checked"</c:if>/>
							</td>
						</tr>
						</c:if>
					</tbody>
				</table>
			</div>
			
			<h3 class="tit_h3">담당자 정보</h3>			
			<div class="btn_bbs type_pm">
				<a href="#appendRow" class="btn_pm" id="managerTableApdRow">+</a>
				<a href="#deleteRow" class="btn_pm" id="managerTableDelRow">-</a>
			</div>
			<div class="table_wrap"><!-- D : table은 div table_wrap 싸고감 -->
				<table summary="휴게소 관리자 테이블 입니다" class="table_list" id="serviceareaManagerTable">
					<caption>휴게소 관리자</caption>
					<colgroup><col width="33.3%" /><col width="33.3%" /><col width="33.3%" /></colgroup>
					<thead>
						<tr>
						<th scope="col">직급</th>
						<th scope="col">이름</th>
						<th scope="col">전화번호</th>
						</tr>
					</thead>
					<tbody>
						<c:if test="${empty resultVO.serviceAreaManagerVOList}">
						<tr id="sampleTr">
							<td><input type="text" name="serviceAreaManagerVOList[0].ssm_job_title" title="직급을 입력하세요" class="width_80"/></td>
							<td><input type="text" name="serviceAreaManagerVOList[0].ssm_manager_name" title="이름을 입력하세요" class="width_80"/></td>
							<td><input type="text" name="serviceAreaManagerVOList[0].ssm_manager_tel" title="TEL 입력하세요" class="width_80"/></td>
						</tr>		
						</c:if>
						<c:if test="${not empty resultVO.serviceAreaManagerVOList}">
							<c:forEach var="result" items="${resultVO.serviceAreaManagerVOList }" varStatus="status"> 
							<tr <c:if test="${status.first }">id="sampleTr"</c:if>>
								<td><input type="text" name="serviceAreaManagerVOList[${status.count-1}].ssm_job_title"  value="${result.ssm_job_title }" title="직급을 입력하세요" class="width_80"/></td>
								<td><input type="text" name="serviceAreaManagerVOList[${status.count-1}].ssm_manager_name"  value="${result.ssm_manager_name }" title="이름을 입력하세요" class="width_80"/></td>
								<td><input type="text" name="serviceAreaManagerVOList[${status.count-1}].ssm_manager_tel"  value="${result.ssm_manager_tel }" title="TEL 입력하세요" class="width_80"/></td>
							</tr>		
							</c:forEach>
						</c:if>
					</tbody>
				</table>
			</div><!--//table_wrap-->
			
			<div class="btn_bbs">
				<c:if test="${loginSessionInfo.admin }">
					<a href="<c:url value='/servicearea/serviceareaList.do' />" onclick="listPage();return false;" class="btn_wh">목록</a>
				</c:if>
				<a href="<c:url value='/servicearea/serviceareaSave.do' />" onclick="saveFormPage();return false;" class="btn_re">저장</a>
			</div>
			<!-- 검색조건 유지 -->
			<input type="hidden" name="pageIndex" id="pageIndex" value="${resultVO.pageIndex }"/>
		</form>
	</div><!--//container_area-->
</div>
<!-- contents e -->
<jsp:include page="../include/footer.jsp" flush="true"/>
